home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / fpc / rexx / getrecord.rexx next >
Encoding:
OS/2 REXX Batch file  |  1998-09-23  |  3.2 KB  |  158 lines

  1. /* getrecord.rexx
  2.  
  3.    This is a rexxscript to scan for pascal records.
  4.  
  5.    I made this one to check my translation of
  6.    cheaders to fpc units. It will write two
  7.    files one pascalfile and one cfile.
  8.  
  9.    The pascalfile you can almost everytime just
  10.    compile with fpc. In the cfile you have to
  11.    make some changes, just put in a line that
  12.    include the cheader for you testprogram.
  13.  
  14.    So if you translate a cheader to fpc just
  15.    let this script check it out, if you get
  16.    the same result from both program you have
  17.    probably made the translation correct.
  18.  
  19.    Usage:
  20.  
  21.    rx getrecord yourunit.pas
  22.  
  23.    nils.sjoholm@mailbox.swipnet.se
  24.  
  25. */
  26.  
  27.  
  28. SIGNAL ON BREAK_C
  29. SIGNAL ON SYNTAX
  30.  
  31. parse arg name
  32.  
  33. if name = '' then do
  34.    say 'Input filename to scan for records'
  35.    parse pull name end
  36.    if name = '' then do
  37.    say 'Error no filename'
  38.    exit 20
  39.    end
  40.    end
  41.  
  42. k = 1
  43.  
  44. thesource = name
  45.  
  46. if index(name,'.') > 0 then do
  47. parse var name thesource '.' extension
  48. end
  49.  
  50. pasname = thesource || 'rec1.pas'
  51. cname = thesource || 'rec2.c'
  52.  
  53. IF ~Open('textfile',name,'READ') THEN DO
  54.     say 'File not found'
  55.     exit 20
  56. end
  57. else do
  58.   say 'Scanning ' || name
  59.   i = 1
  60.   DO WHILE ~eof('textfile')
  61.      line.i = ReadLn('textfile')
  62.      line.i = Strip(line.i)
  63.      myproc = Word(line.i,3)
  64.      myproc = Upper(myproc)
  65.      IF myproc = "RECORD" THEN DO
  66.         CALL CheckLine(line.i)
  67.         SAY "Doing line :" || i
  68.      END
  69.      i = i +1
  70.   END
  71.   CALL Close('textfile')
  72.   if k > 1 then do
  73.      call writepasfile
  74.      call writecfile
  75.      say 'Done'
  76.   end
  77.   else say 'No records found'
  78. END
  79. EXIT
  80.  
  81. pasheader:
  82.        writeln('outfile','Program testrecords;')
  83.        writeln('outfile','')
  84.        writeln('outfile','uses exec,' || thesource || ';')
  85.        writeln('outfile','')
  86.        writeln('outfile','begin')
  87. return
  88.  
  89. writepasfile:
  90.     if ~Open('outfile',pasname,'W') then do
  91.     say 'Can not create file'
  92.     exit 20
  93.     end
  94.     else do
  95.     SAY "Working on " || pasname
  96.     call pasheader
  97.     do j = 1 to k-1
  98.     thename = record.j
  99.     towrite = 'writeln(' || "'" || thename || "',' ':30-length(" || "'" ||thename || "'),"
  100.     towrite = towrite || "':'"
  101.     towrite = towrite || ',sizeof(' || thename || '));'
  102.  
  103.     writeln('outfile',towrite)
  104.     end j
  105.     writeln('outfile','end.')
  106.     writeln('outfile','')
  107.     CALL Close('outfile')
  108.  
  109. RETURN
  110.  
  111. cheader:
  112.     writeln('outfile','');
  113.     writeln('outfile','#include ' || '"stdio.h"')
  114.     writeln('outfile','')
  115.     writeln('outfile','main()')
  116.     writeln('outfile','{')
  117.     return
  118.  
  119. writecfile:
  120.     if ~Open('outfile',cname,'W') then do
  121.     say 'Can not create file'
  122.     exit 20
  123.     end
  124.     else do
  125.     SAY "Working on " || cname
  126.     call cheader
  127.     do j = 1 to k-1
  128.     thename = record.j
  129.     towrite = 'printf(' || '"%-30s:%d\n","' || thename || '",'
  130.     towrite = towrite || 'sizeof(struct ' || right(thename,length(thename)-1) ||'));'
  131.  
  132.     writeln('outfile',towrite)
  133.     end j
  134.     writeln('outfile','}')
  135.     writeln('outfile','')
  136.  
  137.     CALL Close('outfile')
  138. return
  139.  
  140. CheckLine:
  141.     PARSE ARG theline
  142.     parse var theline thename thesep therecord therest
  143.     if thesep = '=' then do
  144.     thename = strip(thename)
  145.     record.k = thename
  146.     k = k +1
  147.     end
  148. RETURN
  149.  
  150.  
  151.  
  152. BREAK_C:
  153. SYNTAX:
  154. SAY "Sorry, error line" SIGL ":" ErrorText(RC) ":-("
  155. EXIT
  156.  
  157.  
  158.